/*
 * Author :zhaoningbo
 * Date   :2011-8-31 下午01:14:33
 * Email  :zhaoningbo@hotmail.com
 * Blog   :http://zhaoningbo.iteye.com/
 */
package grid;

import Ice.ObjectAdapter;

import com.number.operator.MainOperatorI;

public class HelloServer {

    public static void main(String[] args) {

        // 0, 声明执行状态
        int status = 0;
        Ice.Communicator ic = null;

        try {

            // 加载属性文件
            Ice.Properties beforeProperties = Ice.Util.createProperties();
            beforeProperties.setProperty("Ice.MessageSizeMax", "10240");
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = beforeProperties;
            System.out.println(beforeProperties.getProperty("Ice.MessageSizeMax"));
            // 1, 初始化环境
            ic = Ice.Util.initialize(initData);
            Ice.Properties afterProperties = ic.getProperties();
            System.out.println(afterProperties.getProperty("Ice.MessageSizeMax"));

            // 2, 初始化Adapter

            String name = "HelloServer";
            String endpoints = "default -h 127.0.0.1 -p 9999";
            ObjectAdapter objAdapter = ic.createObjectAdapterWithEndpoints(
                    name, endpoints);

            // 3, 创建伺服者
            Ice.Object servant = new MainOperatorI();

            // 4, 添加伺服者至适配器
            objAdapter.add(servant, Ice.Util.stringToIdentity("HelloUID"));

            // 5, 激活
            objAdapter.activate();

System.out.println("<<HelloUID started>>");
            // 6, 等待关闭
            ic.waitForShutdown();

        } catch (Exception e) {
            e.printStackTrace();
            status = 1;
        } finally {
            if (ic != null) {
                ic.destroy();
            }
            System.exit(status);
        }

    }

}
